<template>
  <!--反馈说明新增  -->
  <div >
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="1"
      :labelWidth="110"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
    <div class="dialogBottmView">
      <el-button @click="closeDialog">取 消</el-button>
      <el-button @click="saveDialog" :loading="saveLoading" type="primary">保 存</el-button>
    </div>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { parseTime } from '@/utils';
import { insertDealerApplyOemFeed,updataDealerApplyOemFeed} from '@/api/cms-api/origin/construct/dealer';
export default {
  mixins: [dictionary],
  props: {
    value:{
        type: Object,
        default: null
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      saveLoading: false,
      formData: {}
    };
  },
  mounted() {
    //如果传入参数不为空，则说明是修改进入，初始化对应数据
    if(this.value!=null && (this.value.type=="edit"||this.value.type=="show")){
      this.init();
    }else{
      //新增时，反馈时间默认为当前日期
      this.initForm[2].initialValue = parseTime(new Date(),'{y}-{m}-{d} {h}:{i}:{s}');
    }
  },
  methods: {
    //修改时，初始化页面数据
    init(){
      //循环为表单赋值
      this.initForm.forEach(x => {
          if(x.fieldName=="feedbackTime"){
            x.initialValue =  parseTime(new Date(this.value.rowData[x.fieldName]),'{y}-{m}-{d} {h}:{i}:{s}');
          }else{
            x.initialValue =  this.value.rowData[x.fieldName];
          }
      });
    },
    initFormFun() {
      return [
        {
          type: 'SELECT',
          label: '执行反馈状态',
          fieldName: 'feedbackStatus',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('2549'),
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },{
          type: 'SELECT',
          label: '周度',
          fieldName: 'feedbackWeek',
          placeholder: '请选择',
          initialValue: '',
          itemList: this.createDictList('2576'),
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },
        {
          type: 'DATE',
          label: '反馈时间',
          fieldName: 'feedbackTime',
          valueFormat: 'yyyy-MM-dd HH:mm:ss', //返回数据格式
          initialValue: '',
          placeholder: '请选择',
          style: { width: '100%' },
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'change'
            }
          ]
        },{
          type: 'TEXT_AREA',
          label: '进度说明',
          fieldName: 'processDesc',
          rows:3,
          maxlength:100,
          initialValue: '',
          placeholder:'请输入',
          rules: [
            {
              required: true,
              message: '必填',
              trigger: 'blur'
            }
          ]
        },{
          type: 'TEXT_AREA',
          label: '整改项目',
          fieldName: 'reformItem',
          rows:3,
          maxlength:100,
          initialValue: '',
          placeholder:'请输入'
        }
      ];
    },
    formChangeHandle(val) {
      this.formData = val;
      this.doSaveDialog();
    },
    //保存按钮
    saveDialog() {
      this.$refs.formPanel.SUBMIT_FORM();
    },
    //执行保存
    async doSaveDialog() {
      this.saveLoading = true;
      if(this.value.type == 'add'){
        this.$emit('close', { visible: false,type:'add',data:this.formData});
      }else if(this.value.type == 'edit'){

        this.$emit('close', { visible: false,type:'edit',data:this.formData,rowNo:this.value.rowNo});
      }
      // let submitData = Object.assign({},{"applyId":this.value.applyId},this.formData);
      // let res;
      // //如果传入参数不为空并且为修改
      // if(this.value!=null && this.value.type=="edit"){
      //   res = await updataDealerApplyOemFeed(submitData,this.value.rowData["applyOemFeedbackId"]);
      // }else{
      //   res = await insertDealerApplyOemFeed(submitData);
      // }
      // if (res.resultCode === 200) {
      //   this.$notify.success({title: '提示信息',message:'保存成功!'});
      //   // 重新加载
      //   this.closeDialog('refresh');
      // }else {
      //   this.$notify.error({title: '提示信息',message:res.errMsg||'保存失败!'});
      //   this.closeDialog();
      // }
    },
    //取消操作
    closeDialog(type) {
      this.$emit('close', { visible: false,type:type});
    }
  }
};
</script>